package com.icexxx.icegen.template;

import java.util.HashMap;

import com.icexxx.icegen.codemanager.Count;
import com.icexxx.icegen.codemanager.Data;
import com.icexxx.icegen.codemanager.Template;

public class ResultTemplate implements Template {

    @Override
    public String getCode(HashMap<String, String> dataMap, Data data, String packageName, String className) {
        StringBuilder sum = new StringBuilder();
        String nl = Count.NEWLINE;
        String pack = dataMap.get("domain");
        String projectName = dataMap.get("projectName");
        String pojo = dataMap.get("pojo");
        String ser = dataMap.get("ser");
        String enumPackage = com.icexxx.icegen.utils.Count.ENUM;
        String[][] table = data.getTable(className);
        sum.append("package " + pack + "." + projectName + "." + "util" + ";" + nl);
        String tab = "    ";
        String space = " ";
        sum.append("" + nl);

        sum.append("public class AjaxResult<T> {" + nl);
        sum.append("    private T data;" + nl);
        sum.append("    private int code;" + nl);
        sum.append("    private String msg;" + nl);
        sum.append("	public static <T> AjaxResult<T> success(T data) {" + nl);
        sum.append("		AjaxResult<T> result = new AjaxResult<T>();" + nl);
        sum.append("		result.setData(data);" + nl);
        sum.append("		result.setCode(200);" + nl);
        sum.append("		result.setMsg(\"success\");" + nl);
        sum.append("		return result;" + nl);
        sum.append("	}" + nl);
        sum.append("        public static AjaxResult<String> fail(String string) {" + nl);
        sum.append("            AjaxResult<String> result = new AjaxResult<String>();" + nl);
        sum.append("            result.setData(null);" + nl);
        sum.append("            result.setCode(500);" + nl);
        sum.append("            result.setMsg(\"failure\");" + nl);
        sum.append("            return result;" + nl);
        sum.append("        }" + nl);
        sum.append("	public T getData() {" + nl);
        sum.append("		return data;" + nl);
        sum.append("	}" + nl);
        sum.append("	public void setData(T data) {" + nl);
        sum.append("		this.data = data;" + nl);
        sum.append("	}" + nl);
        sum.append("	public int getCode() {" + nl);
        sum.append("		return code;" + nl);
        sum.append("	}" + nl);
        sum.append("	public void setCode(int code) {" + nl);
        sum.append("		this.code = code;" + nl);
        sum.append("	}" + nl);
        sum.append("	public String getMsg() {" + nl);
        sum.append("		return msg;" + nl);
        sum.append("	}" + nl);
        sum.append("	public void setMsg(String msg) {" + nl);
        sum.append("		this.msg = msg;" + nl);
        sum.append("	}" + nl);
        sum.append("	" + nl);
        sum.append("}" + nl);
        return sum.toString();
    }
}
